import numpy as np
import struct
import argparse


def validate(valid_file: str, source_file: str, result_file: str):
    with open(valid_file, 'wb') as fileSave:
        with open(source_file, 'rb') as fileReader1:
            with open(result_file, 'rb') as fileReader2:
                for i in range(135 * 240 * 3):
                    a = fileReader1.read(1)
                    b = fileReader2.read(1)
                    if a and b:
                        a = struct.unpack('B', a)
                        b = struct.unpack('B', b)
                        fileSave.write(np.uint8(a[0] ^ b[0]))  # 异或运算


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='validate')
    parser.add_argument('-s', '--srcfile', type=str, help='source binary file', default='source.bin')
    parser.add_argument('-r', '--resfile', type=str, help='result binary file', default='res.bin')
    parser.add_argument('-v', '--valfile', type=str, help='validate file', default='val.val')

    arg = parser.parse_args()
    bin_file = arg.srcfile
    decode_bin_file = arg.resfile
    valid_bin_file = arg.valfile
    print(bin_file,decode_bin_file,valid_bin_file)

    # 验证二进制文件
    validate(valid_bin_file, bin_file, decode_bin_file)
